﻿using System;
using System.Collections.Generic;
using System.Text;
using Coder.Object2Report;
using Fee.Orders.ViewModel;
using Fee.Stores;
using Fee.ViewModel;
using Text.Helper;

namespace Fee.IO.Exporters
{
    public class BudgetExporter<T> : BaseExportor<BudgetViewModel>
    where T : FeeDbContext
    {
        private readonly IConstructionTaskStore<T> _constructionTaskStore;

        public BudgetExporter(IConstructionTaskStore<T> constructionTaskStore)
        {
            _constructionTaskStore = constructionTaskStore;
        }

        protected override string SheetName
        {
            get { return "数据"; }
        }

        protected override Report<BudgetViewModel> CreateReportStructure(RenderBase render)
        {

            /* 投资项目编号	逻辑站点名称	专业	提单部门	服务区域	施工单位	施工单位框架合同编号（不显示）	设计单位	设计单位框架合同编号
            （不显示）	监理单位 监理单位框架合同编号
                （不显示）	总投资 施工费用    监理费用 设计费用    甲供物资费用
                */

            var result = new Report<BudgetViewModel>(render);
            result.Column("投资项目编号", f => f.Project.No);
            result.Column("逻辑站点名称", f => f.Station.Name);
            result.Column("专业", f => f.Type.GetEnumDisplayName());
            result.Column("提单部门", f => f.Station.District.Name);
            result.Column("服务区域", f => f.Station.OrderDistrict.Name);
            result.Column("施工单位", f => f.ConstructionContract.Name);
            result.Column("设计单位", f => f.DesignContract.Name);
            result.Column("监理单位", f => f.SupervisorContract.Name);
            result.Column("总投资", f =>
            {

                var effect = f.Cost.ConstructionEffect || f.Cost.SupervisorEffect || f.Cost.DesignEffect;
                return effect ? f.Cost.TotalAmount.ToString("0.00") : "-";
            });
            result.Column("施工费用", f => f.Cost.ConstructionEffect ? f.Cost.Construction.ToString("0.00") : "-");
            result.Column("监理费用", f => f.Cost.SupervisorEffect ? f.Cost.Supervisor.ToString("0.00") : "-");
            result.Column("设计费用", f => f.Cost.DesignEffect ? f.Cost.Design.ToString("0.00") : "-");
            result.Column("甲供物资费用", f =>
            {
                var effect = f.Cost.ConstructionEffect || f.Cost.SupervisorEffect ||f.Cost.DesignEffect;
                return effect ? f.Cost.FirstPartyMeteria.ToString("0.00") : "-";
            });
            return result;
        }
    }
}
